package test0103.test02;

public class Company {
    private String com_name;
    Department[] departments = new Department[100];
    int num_departments = 0;
    public Company() {
    }

    public Company(String com_name) {
        this.com_name = com_name;
    }

    public String getCom_name() {
        return com_name;
    }

    public void setCom_name(String com_name) {
        this.com_name = com_name;
    }

    @Override
    public String toString() {
        return "Company{" +
                "com_name='" + com_name + '\'' +
                '}';
    }

    public void addDepartment(Department department) {
        this.departments[num_departments] = department;
        num_departments++;
    }

    public Department getDepartmentByName(String 开发部) {
        for (int i = 0; i < num_departments; i++) {
            if (departments[i].getDepartment_name().equals(开发部)) {
                return departments[i];
            }
        }
        return null;
    }

    public Position getPositionByName(String positon_name) {
        for (int i = 0; i < num_departments; i++) {
            for(int j = 0; j < departments[i].num_positions; j++){
                if (departments[i].getPositions()[j].getPosition_name() == positon_name) {
                    return departments[i].getPositions()[j];
                }
            }
        }
        return null;
    }

    public Employee getEmployeeByName(String employee_name) {
        for (int i = 0; i < num_departments; i++) {
            for(int j = 0; j < departments[i].num_positions; j++){
                for(int k = 0; k < departments[i].getPositions()[j].num_employees; k++){
                    if (departments[i].getPositions()[j].getEmployees()[k].getEmp_name() == employee_name) {
                        return departments[i].getPositions()[j].getEmployees()[k];
                    }
                }
            }
        }
        return null;
    }
}
